{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import StandardScaler"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 5.  ],\n",
       "       [ 8.75],\n",
       "       [ 7.5 ],\n",
       "       [10.  ]])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.preprocessing import MinMaxScaler\n",
    " \n",
    "data = [[-1, 2], [-0.5, 6], [0, 10], [1, 18]]\n",
    "data = [[-1],[0.5],[0],[1]]\n",
    "#如果换成表是什么样子？\n",
    "import pandas as pd\n",
    "pd.DataFrame(data)\n",
    " \n",
    "#实现归一化\n",
    "scaler = MinMaxScaler(feature_range=[5,10])                             #实例化\n",
    "scaler = scaler.fit(data)                           #fit，在这里本质是生成min(x)和max(x)\n",
    "result = scaler.transform(data)                     #通过接口导出结果\n",
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.1, 7.6, 0. ])"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.preprocessing import StandardScaler\n",
    "data = [[-1, 2,-3], [-0.5, 6,-1], [0, 10,0], [1, 18,1],[1,2,3]]\n",
    " \n",
    "scaler = StandardScaler()                           #实例化\n",
    "scaler.fit(data)                                    #fit，本质是生成均值和方差\n",
    " \n",
    "scaler.mean_                                        #查看均值的属性mean_\n",
    "#scaler.var_                                         #查看方差的属性var_\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_std = scaler.transform(data)                      #通过接口导出结果\n",
    " \n",
    "x_std.mean()                                        #导出的结果是一个数组，用mean()查看均值\n",
    "#x_std.std()                                         #用std()查看方差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1.375     , -0.93541435, -1.5       ],\n",
       "       [-0.75      , -0.26726124, -0.5       ],\n",
       "       [-0.125     ,  0.40089186,  0.        ],\n",
       "       [ 1.125     ,  1.73719807,  0.5       ],\n",
       "       [ 1.125     , -0.93541435,  1.5       ]])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_std"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.4499999999999997"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0.7**2 + 1.4**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.9599999999999997"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1.4**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
